define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/wages/index',
                    add_url: 'finance/wages/add',
                    edit_url: 'finance/wages/edit',
                    del_url: 'finance/wages/del',
                    multi_url: 'finance/wages/send',
                    import_url: 'finance/wages/import',
                    table: 'wages',
                }
            });

            var table = $("#table");
            //在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='department']", form).addClass("selectpage").data("source", "finance/wages/department").data("primaryKey", "department").data("field", "department").data("orderBy", "id desc");

                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'yanfa', title: __('Yanfa'), searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.normal,operate:false},
                        {field: 'zhuanye', title: __('Zhuanye'),operate:false},
                        {field: 'ruzhi', title: __('Ruzhi'),operate:false},
                        {field: 'xueli', title: __('Xueli'),operate:false},
                        {field: 'gangwei', title: __('Gangwei'),operate:false},
                        {field: 'xiangmu', title: __('Xiangmu')},
                        {field: 'username', title: __('Username'),operate:false},
                        {field: 'wageslist.user_id', title: __('用户标识'),operate:false},
                        {field: 'department', title: __('所属部门'),operate:false},
                        {field: 'shenfenzheng', title: __('Shenfenzheng'),operate:false},
                        // {field: 'wageslist.shenfenzheng', title: __('Wageslist.shenfenzheng')},
                        {field: 'wageslist.base_pay', title: __('Wageslist.base_pay'), operate:false},
                        {field: 'wageslist.hfbt', title: __('Wageslist.hfbt'), operate:false},
                        {field: 'wageslist.jtbt', title: __('Wageslist.jtbt'), operate:false},
                        {field: 'wageslist.yxygbt', title: __('Wageslist.yxygbt'), operate:false},
                        {field: 'wageslist.glbt', title: __('Wageslist.glbt'), operate:false},
                        {field: 'canbu', title: __('Canbu'), operate:false},
                        {field: 'qitabutie', title: __('Qitabutie'), operate:false},
                        {field: 'koukuan', title: __('Koukuan'), operate:false},
                        {field: 'yingfagongzi', title: __('Yingfagongzi'), operate:false},

                        {field: 'wageslist.ylbx', title: __('Wageslist.ylbx'), operate:false},
                        {field: 'wageslist.yilbx', title: __('Wageslist.yilbx'), operate:false},
                        {field: 'wageslist.sybx', title: __('Wageslist.sybx'), operate:false},
                        {field: 'wageslist.zfgjj', title: __('Wageslist.zfgjj'), operate:false},
                        {field: 'suodeshui', title: __('Suodeshui'), operate:false},
                        {field: 'bukoushuier', title: __('Bukoushuier'), operate:false},
                        {field: 'shifagongzi', title: __('Shifagongzi'), operate:false},
                        {field: 'yingfaheji', title: __('Yingfaheji'), operate:false},
                        {field: 'jiabanbanshui', title: __('Jiabanbanshui'), operate:false},
                        {field: 'jixiaobanshui', title: __('Jixiaobanshui'), operate:false},
                        {field: 'jixiaobanshuixiaoji', title: __('Jixiaobanshuixiaoji'), operate:false},
                        {field: 'feixiaobanshui', title: __('Feixiaobanshui'), operate:false},
                        {field: 'banshuiheji', title: __('Banshuiheji'), operate:false},
                        {field: 'koufa', title: __('Koufa'), operate:false},
                        {field: 'yingfabanshui', title: __('Yingfabanshui'), operate:false},
                        {field: 'banshuishuijin', title: __('Banshuishuijin'), operate:false},
                        {field: 'banshuishifa', title: __('Banshuishifa'), operate:false},
                        {field: 'zongticheng', title: __('Zongticheng'), operate:false},
                        {field: 'beizhu', title: __('备注'),operate:false},

                        {field: 'wageslist.feixiao', title: __('Wageslist.feixiao'),operate:false},
                        {field: 'xiaoshoutaoshu', title: __('Xiaoshoutaoshu'),operate:false},
                        {field: 'year', title: __('Year'),operate:false},

                        {field: 'year', title: __('Year'),visible: false,formatter: Table.api.formatter.datetime,type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM"'},
                        {field: 'department', title: __('所属部门'), visible: false,formatter: Table.api.formatter.search},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});